﻿namespace EyeOpen.Validation.Test
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using SharpTestsEx;

    /// <summary>
    /// Tests the <see cref="MinimumLengthValidator"/> class.
    /// </summary>
    [TestClass]
    public class LengthValidatorTest
    {
        private readonly IValidator validator = new MinimumLengthValidator(5);

        /// <summary>
        /// Accesses to ValidationMessage property of <see cref="MinimumLengthValidator"/> without call IsValid method expected an exception.
        /// </summary>
        [TestMethod]
        [Owner("Matteo Migliore")]
        [Description("Unit.CodeBase.Validation")]
        [ExpectedException(typeof(InvalidOperationException))]
        public void AccessToValidationMessagePropertyOfLengthValidatorWithoutCallIsValidMethodExpectedAnException()
        {
            var validationMessage = 
                validator
                    .ValidationMessage;
        }

        /// <summary>
        /// Validates an empty string expected validation fails.
        /// </summary>
        [TestMethod]
        [Owner("Matteo Migliore")]
        [Description("Unit.CodeBase.Validation")]
        public void LengthValidatorValidateAnEmptyStringExpectedValidationFails()
        {
            validator
                .IsValid(string.Empty)
                .Should("LengthValidator validate well an empty string.")
                .Be
                .False(); 
        }

        /// <summary>
        /// Validates a <c>null</c> string expected validation fails.
        /// </summary>
        [TestMethod]
        [Owner("Matteo Migliore")]
        [Description("Unit.CodeBase.Validation")]
        public void LengthValidatorValidateANullStringExpectedValidationFails()
        {                                           
            validator
                .IsValid(null)
                .Should("LengthValidator validate well a null string.")
                .Be
                .False();
        }

        /// <summary>
        /// <see cref="MinimumLengthValidator"/> validate a valid string of allowed length expected validation pass.
        /// </summary>
        [TestMethod]
        [Owner("Matteo Migliore")]
        [Description("Unit.CodeBase.Validation")]
        public void LengthValidatorValidateAValidStringOfAllowedLengthExpectedValidationPass()
        {
            const string Value = "123";

            validator
                .IsValid(Value)
                .Should("LengthValidator validate correct a not valid string of required minimum length.")
                .Be
                .False();
        }

        /// <summary>
        /// <see cref="MinimumLengthValidator"/> validate a longer string expected validation fails.
        /// </summary>
        [TestMethod]
        [Owner("Matteo Migliore")]
        [Description("Unit.CodeBase.Validation")]
        public void LengthValidatorValidateALongerStringExpectedValidationFails()
        {
            const string Value = "123";

            validator
                .IsValid(Value)
                .Should("LengthValidator validate well a string longer than specified.")
                .Be
                .False();
        }
    }
}